<template>
  <!--饼图-->
  <div
    :style="{width:width,height:height}"
  ></div>
</template>

<script>
  export default {
    name: 'PieChart',
    props: {
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '100%'
      },
      /**
       * @param:
       *    dataLine  --> 数据
       * @date 2020/08/23
       * @author ZhuHongWei
       */
      chartData: {
        type: Object,
        default: () =>{}
      },
      barColor: {
        type: String,
        default: '#58A3F7'
      }
    },
    data() {
      return {}
    },
    watch: {
      chartData: {
        deep: true,
        handler: function() {
          this.initChart()
        }
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    methods: {
      initChart() {
        this.chart = this.$echarts.init(this.$el)
        this.chart.clear()
        let option = {
          color: ['#58D5FF', '#73ACFF', '#FDD56A', '#FDB36A', '#FD866A', '#f48c06'],
          title: {
            show: false
          },
          grid: {
            left: '0%',
            right: '0%',
            bottom: '30%',
            top: '0'
          },
          tooltip: {
            trigger: 'item'
          },
          legend: {
            textStyle: {
              color: '#B4B4B4'
            },
            orient: 'vertical',
            left: '-2%',
            top: 'center'
          },
          series: [
            {
              center: ['65%', '50%'],
              label: {
                position: 'inner',
                fontSize: 10,
                formatter:function(val){
                  return `${val.percent}%`
                }
              },
              name: '',
              type: 'pie',
              radius: '70%',
              avoidLabelOverlap: false,
              data: this.chartData.dataList,
              emphasis: {
                itemStyle: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
              }
            }
          ]
        }
        this.chart.setOption(option)
      }
    }
  }
</script>

<style scoped>
</style>
